package com.shanzhe.eshop.common.jdk;

import lombok.SneakyThrows;

import java.util.concurrent.Semaphore;

/**
 * @Author yinwei
 * @create 2021/12/13
 * @Version 1.0
 */
public class SemaphoneDemo {

    public static void main(String[] args) throws InterruptedException {
        final Semaphore semaphore = new Semaphore(0);

        new Thread(){
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(1000);
                System.out.println("线程1执行。。。。");
                semaphore.release();
            }
        }.start();

        new Thread(){
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(1000);
                System.out.println("线程2执行。。。。");
                semaphore.release();
            }
        }.start();

        semaphore.acquire(1);
        System.out.println("main线程执行。。。。");
    }
}
